﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using CE.Global;

public partial class Provider_CarInsurance_ViewProviderCarCoverageType : System.Web.UI.Page
{
    string PageName = "CXCI";
    string SubPageName = "CXCICT";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session[CE.Global.General.UserId] == null || Session[CE.Global.General.ProviderCompanyId] == null)
        {
            Response.Redirect("~/Provider/ProviderSecureLogin.aspx");
        }
        CheckMainPageAccess();
        CheckSubPageAccess();

        //if (Session[CE.Global.General.ProviderCompanyId].ToString() == CE.Configuration.MyConfigurationManager.GetAppSettingValue("LibertyProviderCompanyId"))
        //{
        //    lnkNewClaimInfo.NavigateUrl = "~/Provider/CarInsurance/AddNewLibertyInsurance.aspx";
        //}
        //else if (Session[CE.Global.General.ProviderCompanyId].ToString() == CE.Configuration.MyConfigurationManager.GetAppSettingValue("EtiqaProviderCompanyId"))
        //{
        //    lnkNewClaimInfo.NavigateUrl = "~/Provider/CarInsurance/AddNewEtiqaInsurance.aspx";
        //}
        
    }

    protected void ibtBack_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("~/Provider/CarInsurance/TableMatching.aspx");
    }

    protected void gvCoverType_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        string pagetoredirect = "";

        if (Session[CE.Global.General.ProviderCompanyId].ToString() == CE.Configuration.MyConfigurationManager.GetAppSettingValue("LibertyProviderCompanyId"))
        {
            pagetoredirect = "AddNewLibertyInsurance.aspx?CXCoverTypeId=";
        }
        else if (Session[CE.Global.General.ProviderCompanyId].ToString() == CE.Configuration.MyConfigurationManager.GetAppSettingValue("EtiqaProviderCompanyId"))
        {
            pagetoredirect = "AddNewEtiqaInsurance.aspx?CXCoverTypeId=";
        }

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            HyperLink lnkSelect = new HyperLink();
            lnkSelect = (HyperLink)e.Row.Cells[11].FindControl("lnkSelect");

            Label lblID = new Label();
            lblID = (Label)e.Row.Cells[11].FindControl("lblCoverID");

            lnkSelect.NavigateUrl = pagetoredirect + lblID.Text.Trim();
        }
    }

    private void CheckMainPageAccess()
    {
        Int64 PageAccess = General.GetProviderMainPageAccess(Convert.ToInt64(Session[General.ProviderCompanyId].ToString()),
                                                        Convert.ToInt64(Session[General.UserId].ToString()), PageName);
        if (PageAccess == 0)
        {
            //Response.Redirect("~/Provider/UserMessage.aspx?errorcode=2000");
            Response.Redirect("~/Provider/UserMessage.aspx?mt=UM&ec=2000");
        }
    }

    private void CheckSubPageAccess()
    {
        Int64 PageAccess = General.GetProviderSubPageAccess(Convert.ToInt64(Session[General.ProviderCompanyId].ToString()),
                                                        Convert.ToInt64(Session[General.UserId].ToString()), SubPageName);
        if (PageAccess == 0)
        {
            //Response.Redirect("~/Provider/UserMessage.aspx?errorcode=2000");
            Response.Redirect("~/Provider/UserMessage.aspx?mt=UM&ec=2000");
        }
        else if (PageAccess == 100)
        {
            lnkNewClaimInfo.Visible = false;
        }
    }


}
